package indi.zhifa.study2024.nbr.controller;

import indi.zhifa.core.common.web.entity.ann.ZhiFaRestController;
import indi.zhifa.core.common.web.entity.exception.ServiceException;
import indi.zhifa.study2024.nbr.logic.report.test.entity.mapperIn.SelectTestEntityMapperIn;
import indi.zhifa.study2024.nbr.logic.report.test.entity.vo.TestEntityVo;
import indi.zhifa.study2024.nbr.logic.report.test.service.IReportTestService;
import indi.zhifa.study2024.nbr.logic.test.entity.TestWhoImIResponse;
import indi.zhifa.study2024.nbr.logic.test.service.IWhoImIService;
import indi.zhifa.study2024.nbr.properties.AppProperties;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static indi.zhifa.study2024.nbr.util.Constant.ControllerTestPrefix;

@Slf4j
@Validated
@RequiredArgsConstructor
@RequestMapping(value = ControllerTestPrefix)
@ZhiFaRestController
@Tag(name = "测试接口")
public class TestController {

    private final IWhoImIService mWhoImIService;
    private final IReportTestService mReportTestService;

    @Operation(summary = "hello")
    @PostMapping("/hello")
    public String hello(){
        return "hello2";
    }

    @Operation(summary = "whoImI")
    @GetMapping("/whoImI")
    public TestWhoImIResponse whoImI(@RequestHeader(value = "auth_data", required = false) String pAuthHeader){
        if(StringUtils.hasText(pAuthHeader)){
            log.info("获取到权限信息头"+pAuthHeader);
            return mWhoImIService.whoImI(pAuthHeader);
        }else{
            throw new ServiceException("没有获取到auth_data");
        }
    }

    @Operation(summary = "selectTestEntityList")
    @GetMapping("/hello")
    public List<TestEntityVo> selectTestEntityList(@ModelAttribute SelectTestEntityMapperIn pMapperIn){
        return mReportTestService.selectTestEntity(pMapperIn);
    }


}
